﻿#region Copyright 
/*-------------------------------------------------------------------------
* 命名空间名称/文件名:    SSPivot.AspNetCore.Repository.DbContext/DbContextExtensions 
* CLR版本:     4.0.30319.42000
* 机器名称:    DESKTOP-NHMLO8A
* 功 能：       N/A
* 类 名：       DbContextExtensions
* 创建时间：  2025/5/26 14:44:13
* 版本号：      v1.0
* 创建人:        xulong
*-------------------------------------------------------------------------*/
#endregion
using Microsoft.EntityFrameworkCore;
using SSPivot.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSPivot.AspNetCore.Repository
{
    public static class DbContextExtensions
    {
        public static DbContextOptionsBuilder UseDatabase(
            this DbContextOptionsBuilder builder,
            DatabaseType dbType,
            string connectionString)
        {
            return dbType switch
            {
                DatabaseType.SqlServer => builder.UseSqlServer(connectionString),
                DatabaseType.MySql => builder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)),
                DatabaseType.SQLite => builder.UseSqlite(connectionString),
                _ => throw new ArgumentOutOfRangeException(nameof(dbType))
            };
        }
    }
}
